package com.markhsiu;

import com.alibaba.AAliServer;
import com.alibaba.BAliServer;
import com.markhsiu.bean.App;
import com.markhsiu.tools.FileUtils;

import java.io.BufferedReader;
import java.util.HashMap;
import java.util.Map;

/**
 * 可以考虑计算下，cpu\mem的最大值和最小值
 * @author Mark Hsiu
 */
public class AppAsys {


    public static void main(String[] args) throws Exception {
        getAppMap(BAliServer.PATH_APP);
    }

    public static Map<String,App> getAppMap(String path)throws  Exception{
        Map<String,App> appMap = new HashMap<>();

        BufferedReader bs = FileUtils.readLines(path);

        int len = 7;
        for (String line = bs.readLine(); line != null; line = bs.readLine()) {
            String[] pair = line.split(",", -1);
            if (pair.length != len) {
                throw new Exception("Invaild solution file");
            }

            String id = pair[0];


            String[] cpus = pair[1].split("\\|",-1);
            double maxCpu = 0;
            for(int i=0;i< cpus.length;i++){
                double tmp = Double.parseDouble(cpus[i]);
                if(tmp > maxCpu){
                    maxCpu = tmp;
                }
            }
            String[] mems = pair[2].split("\\|");
            double maxMem = 0;
            for(int i=0;i< mems.length;i++){
                double tmp = Double.parseDouble(mems[i]);
                if(tmp > maxMem){
                    maxMem = tmp;
                }
            }

            App app = new App();
            app.id = id;
            app.maxCpu = maxCpu;
            app.maxMem = maxMem;
            app.disk = Integer.parseInt(pair[3]);
            app.p = Integer.parseInt(pair[4]);
            app.m = Integer.parseInt(pair[5]);
            app.pm = Integer.parseInt(pair[6]);
            appMap.put(id, app);
        }


        System.out.println(appMap.size());
        return appMap;
    }
}

